//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.neurosky.thinkgear;

import com.neurosky.thinkgear.FFTResult;

public class FFT {
    private float[] a;
    private float[] b;

    public FFT() {
    }

    public FFTResult calculateFFT(float[] var1, float[] var2, int var3, int var4) {
        this.a = new float[var4];
        this.b = new float[var4];
        System.arraycopy(var1, 0, this.a, 0, Math.min(var1.length, var4));
        System.arraycopy(var2, 0, this.b, 0, Math.min(var2.length, var4));
        int var9 = (int)(Math.log((double)this.a.length) / Math.log(2.0D));
        int var16 = 1;

        int var17;
        for(var17 = 0; var17 < var9; ++var17) {
            var16 <<= 1;
        }

        int var6 = var16 >> 1;
        int var5 = 0;

        for(var17 = 0; var17 < var16 - 1; ++var17) {
            if(var17 < var5) {
                float var19 = this.a[var17];
                float var7 = this.b[var17];
                this.a[var17] = this.a[var5];
                this.b[var17] = this.b[var5];
                this.a[var5] = var19;
                this.b[var5] = var7;
            }

            for(var4 = var6; var4 <= var5; var4 >>= 1) {
                var5 -= var4;
            }

            var5 += var4;
        }

        float var10 = -1.0F;
        float var11 = 0.0F;
        int var8 = 1;

        for(var6 = 0; var6 < var9; ++var6) {
            int var20 = var8;
            var8 <<= 1;
            float var14 = 1.0F;
            float var15 = 0.0F;

            for(var5 = 0; var5 < var20; ++var5) {
                for(var17 = var5; var17 < var16; var17 += var8) {
                    var4 = var17 + var20;
                    float var12 = var14 * this.a[var4] - var15 * this.b[var4];
                    float var13 = var14 * this.b[var4] + var15 * this.a[var4];
                    this.a[var4] = this.a[var17] - var12;
                    this.b[var4] = this.b[var17] - var13;
                    this.a[var17] += var12;
                    this.b[var17] += var13;
                }

                float var18 = var14 * var10 - var15 * var11;
                var15 = var14 * var11 + var15 * var10;
                var14 = var18;
            }

            var11 = (float)Math.sqrt((1.0D - (double)var10) / 2.0D);
            if(var3 == 1) {
                var11 = -var11;
            }

            var10 = (float)Math.sqrt((1.0D + (double)var10) / 2.0D);
        }

        if(var3 == -1) {
            for(var17 = 0; var17 < var16; ++var17) {
                this.a[var17] /= (float)var16;
                this.b[var17] /= (float)var16;
            }
        }

        return new FFTResult(this.a, this.b);
    }
}
